//
//  SLPopCustomController.m
//  Objective-C
//
//  Created by S_Line on 2018/7/11.
//  Copyright © 2018年 S_Line. All rights reserved.
//

#import "SLPopCustomController.h"

#import <pop/POP.h>

@interface SLPopCustomController ()

@property (nonatomic, weak) UILabel *countLabel;

@end

@implementation SLPopCustomController

- (void)initNavBar {
    self.navTitle = @"Custom 自定义动画";
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initNavBar];
    
    [self initView];
}

- (void)initView {
    UILabel *countLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, kNavigationBarHeight + 20, kScreenWidth - 30, 30)];
    countLabel.textColor = [UIColor blackColor];
    self.countLabel = countLabel;
    [self.view addSubview:countLabel];
    
    [self animate1];
}

- (void)animate1 {
    POPAnimatableProperty *prop = [POPAnimatableProperty propertyWithName:@"time" initializer:^(POPMutableAnimatableProperty *prop) {
        // 告诉pop当前的属性值
        prop.readBlock = ^(id obj, CGFloat *values) {
            NSLog(@"-----readBlock - obj : %@-----", NSStringFromClass([obj class]));
            NSLog(@"-----readBlock - value[0] : %f-----", values[0]);
            NSLog(@"");
//            NSLog(@"-----readBlock%f - value[1] : -----", values[1]);
        };
        // 修改变化后的属性值
        prop.writeBlock = ^(id obj, const CGFloat *values) {
            NSLog(@"-----writeBlock - obj : %@-----", NSStringFromClass([obj class]));
            NSLog(@"-----writeBlock - value[0] : %f-----", values[0]);
            NSLog(@"-----readBlock%f - value[1] : -----", values[1]);
            NSLog(@"");
            UILabel *label = (UILabel *)obj;
//            label.text = [NSString stringWithFormat:@"%.2d:%.2d:%.2d", (int)values[0] / 60, (int)values[0] % 60, (int)(values[0] * 100) % 100];
            label.text = [NSString stringWithFormat:@"%.0f", values[0]];
        };
        // 动画变化的快慢, 值越大block调用次数越少
        prop.threshold = 0.1;
    }];
    
    // 1.初始化
    POPBasicAnimation *anim = [POPBasicAnimation linearAnimation];
    
    // 自定义属性
    anim.property = prop;
    
    // 设置初始值
    anim.fromValue = @0;
    anim.toValue = @(28888);
    
    // 动画时长
    anim.duration = 1;
//    anim.beginTime = CACurrentMediaTime() + 1.f;
    [self.countLabel pop_addAnimation:anim forKey:@"countLabel"];
    
}

@end
